JBoss Community Archive (Read Only)

Graphene 1

Command Interception

An advanced theme is the command interception. The basics of this technique comes from Aspect Oriented Programming.

The interceptor is basically the code which will be performed around invocation of selenium command.

This way, you can:

Command Interceptor

For this purpose, you have to implement interface CommandInterceptor - it requires to implement method

void intercept(CommandContext ctx) throws CommandInterceptionException;

where you implement the interception code.

If you will implement this method, you must additionally satisfy interceptor contract - the CommandContext#invoke() method must be invoked at least once - otherwise, after end of intercept(...) method, the  CommandInterceptionException will be thrown and test will fail.

Warning: satisfying the contract mentioned above is checked at runtime, not at compile-time

Command context

You get to disposition the CommandContext object in intercept method. On the context, you have to call the CommandContext#invoke() method. You can also obtain the current command name and it's arguments here.

The implementation of invocation nesting can be seen on CommandContext.

Command Interceptor Proxy

Registration and unregistration of interceptors to selenium commands is provided by CommandInterceptorProxy, which is the member of GrapheneSelenium.

On the CommandInterceptorProxy can be registered zero and more interceptors, which will be in sequence called to achieve desired functionality, whereas each interceptor's body is nested into the other, using CommandContext#invoke() method. The call of invoke for last of the interceptors in sequence will cause actual performing of the command.

The entry point for command execution, AjaxSelenium, contains one  CommandInterceptionProxy, which triggers all the command through sequence of interceptors registered to it.

Two well-known implementation of CommandInterceptionProxy are RequestTypeGuard and AjaxAwareInterceptor.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:13:27 UTC, last content change 2012-03-16 14:23:18 UTC.